package com.mephi.oshs.model.style;

import com.mephi.oshs.Main;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.osgi.framework.Bundle;

import java.io.IOException;

/**
 * Фабрика порождающая стили для узлов дерева ОШС,
 * которые будут содержать в себе элементы дерева ОШС.
 */
public class StyleFactory {

    private static final Display DISPLAY = Display.getDefault();
    private static final IStyle STYLE = new Style(DISPLAY.getSystemImage(SWT.ICON_INFORMATION));
    private static final IStyle STYLE2 = new Style(DISPLAY.getSystemImage(SWT.ICON_QUESTION));
    private static final IStyle STYLE3 = new Style(DISPLAY.getSystemImage(SWT.ICON_WARNING));
    private static final IStyle STYLE4 = new Style(DISPLAY.getSystemImage(SWT.ICON_ERROR));
    private static final Image EMPTY = new Image(DISPLAY, getBlankIconFilePath());

    private static String getBlankIconFilePath() {
        try {
            final Bundle bundle = Main.getBundleContext().getBundle();
            return FileLocator.toFileURL(bundle.getEntry("resources/icons/blank.png")).getFile();
        } catch (IOException e) {
            return "";
        }
    }

    public static Image getBlankImage() {
        return EMPTY;
    }

    public static IStyle getDefaultStyle() {
        return DefaultStyle.getInstance();
    }

    public static IStyle getStyle() {
        return STYLE;
    }

    public static IStyle getStyle2() {
        return STYLE2;
    }

    public static IStyle getStyle3() {
        return STYLE3;
    }

    public static IStyle getStyle4() {
        return STYLE4;
    }
}